/*
** Line Protocol Connection Library
** Copyright (C) 2008 Eric Day
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to:
** Free Software Foundation, Inc.
** 51 Franklin Street, Fifth Floor,
** Boston, MA  02110-1301, USA
*/

#ifndef _LPC_H
#define _LPC_H

#include "config.h"

#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#if HAVE_POLL_H
#include <poll.h>
#endif
#if HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif

struct _LPC;
typedef struct _LPC LPC;

/*
** lpc functions
*/

/* create a new lpc by connecting to server:port */
int lpc_connect(LPC **new_lpc, struct pollfd *pfd, char *server, uint16_t port);

/* create a new lpc from an existing socket */
int lpc_create(LPC **new_lpc, struct pollfd *pfd, int socket);

/* create a new lpc that listens on a port */
int lpc_listen(LPC **new_lpc, struct pollfd *pfd, uint16_t port, int backlog);

/* accept a new connection from a listening lpc */
int lpc_accept(LPC *lpc, int *socket);

/* close a lpc */
void lpc_close(LPC *lpc);

/* destroy a lpc */
void lpc_destroy(LPC *lpc);

/* take care of socket activity, possibly returning a line */
int lpc_activity(LPC *lpc);

/* read a line from a lpc */
int lpc_read(LPC *lpc, char *buf, int len);

/* write a line to a lpc */
int lpc_write(LPC *lpc, char *buf, int len);

/* printf a line to a lpc */
int lpc_printf(LPC *lpc, char *format, ...);

/* get status string */
char *lpc_status(LPC *lpc);

#endif /* _LPC_H */
